
'use strict';

function calculate_average(collection){
      let count = 0;
      let total = 0;
      collection.map((item)=>{
        if(item%2 === 0){
          total += item;
          count ++;
        }
      });
     return parseInt(total/count);
}

function even_group_calculate_average(collection){
    collection = collection.filter((item,value)=>{
        if(value%2 !== 0){
            if(item % 2 === 0){
                return item ;
            }
        }
    })
    let obj = {} ;
    for(let value of collection){
        let key = value.toString().length ;
        if(!obj[key]){
            obj[key] = [] ;
            obj[key].push(value) ;
        }else{
            obj[key].push(value) ;
        }
    }
    let result = [] ;
    for(let key in obj){
        result.push(calculate_average(obj[key]));
    }
    return result ;
};



module.exports = even_group_calculate_average;

'use strict';
function even_group_calculate_average(collection){
    let arrEven=[],
        res=[],
        result=[];
    let a=[],
        b=[],
        c=[];
    for(let i=0;i<collection.length;i++){
        if(i%2!==0){
           arrEven.push(collection[i]); 
        }
    }
    for(let item of arrEven){
        if(item%2===0){
            result.push(item);
        }
    }
    if(result.length===0){
        res=[0];
    }else{
        for(let item of result){
            if(item/1>=1&&item/1<10){
                a.push(item);
            }else if(item/1>=10&&item/1<100){
                b.push(item);
            }else if(item/1>=100&&item/1<1000){
                c.push(item);
            }  
        }
        if(a.length>0){
            res.push(a.reduce(function(init,next){return init+next;},0)/a.length); 
        }
        if(b.length>0){
            res.push(b.reduce(function(init,next){return init+next;},0)/b.length);
        }
        if(c.length>0){
            res.push(c.reduce(function(init,next){return init+next;},0)/c.length);
        }
    }
    return res;
};

var collection_a = [1, 2, 3, 4, 5, 6, 12, 454, 324, 21, 45, 644, 34, 56, 345, 570, 8, 4, 14];
var result = even_group_calculate_average(collection_a);
console.log(result);

module.exports = even_group_calculate_average;


